package com.ioidea.holland.view

import android.view.View
import androidx.appcompat.app.AppCompatActivity
import com.blankj.utilcode.util.TimeUtils
import com.ioidea.base.util.MyLogger
import com.lxj.xpopup.XPopup
import com.lxj.xpopupext.listener.TimePickerListener
import com.lxj.xpopupext.popup.TimePickerPopup
import java.util.Calendar
import java.util.Date

fun AppCompatActivity.showTimePicker(onTimeConfirmListener: (timeStr: String) -> Unit) {
    val startDate = Calendar.getInstance().apply {
        set(2000, 1, 1)
    }
    val endDate = Calendar.getInstance()

    val popup = TimePickerPopup(this) //
        .setDefaultDate(endDate)  //设置默认选中日期
        .setYearRange(1990, endDate.weekYear) //设置年份范围
        .setDateRange(startDate, endDate) //设置日期范围
        .setTimePickerListener(object : TimePickerListener {
            override fun onTimeChanged(date: Date?) {
            }

            override fun onTimeConfirm(date: Date, view: View) {
                val timeStr = TimeUtils.date2String(date, "yyyy-MM-dd")
                MyLogger.hLog().e("timeStr:$timeStr")
                onTimeConfirmListener(timeStr)
            }

            override fun onCancel() {
            }
        })

    XPopup.Builder(this)
        .asCustom(popup)
        .show()
}



